/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.bar;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JToolBar;

import org.jxSwing.border.BevelBorderFactory;
import org.jxSwing.border.EtchedBorderFactory;
import org.jxSwing.component.label.CapsLookKeyLabel;
import org.jxSwing.component.label.LocaleLabel;
import org.jxSwing.component.label.NumLookKeyLabel;
import org.jxSwing.component.label.OperatingSystemLabel;
import org.jxSwing.component.label.ScrollLookKeyLabel;
import org.jxSwing.component.label.TimerLabel;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.panel
 * @date 04/02/2014 - 22:02:10
 */
public final class StatusBar extends JToolBar {
	
	private static final long serialVersionUID = 8039268911835570173L;
	
	private static final int[] COLUMN_WIDTHS = new int[]{50, 50, 50, 50, 50, 0, 50, 0};
	
	private JPanel panel = null;
	
	private CapsLookKeyLabel lblCapsLookKey = null;
	
	private NumLookKeyLabel lblNumLookKey = null;
	
	private ScrollLookKeyLabel lblScrollLookKey = null;
	
	private LocaleLabel lblLocale = null;
	
	private JLabel lblMessage;
	
	private JProgressBar progressBar = null;
	
	private TimerLabel lblTimer;
	
	private OperatingSystemLabel lblOperatingSystem;
	
	/**
	 * 
	 */
	public StatusBar() {
	
		initGUI();
	}
	
	/**
	 * @return the oanel
	 */
	private JPanel getPanel() {
	
		if(panel == null) {
			panel = new JPanel();
			
			final GridBagLayout gridBagLayout = new GridBagLayout();
			gridBagLayout.columnWidths = COLUMN_WIDTHS;
			gridBagLayout.rowHeights = new int[]{0, 0};
			gridBagLayout.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0};
			gridBagLayout.rowWeights = new double[]{0.0, Double.MIN_VALUE};
			
			panel.setLayout(gridBagLayout);
			
			final GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
			gridBagConstraints1.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints1.gridx = 0;
			gridBagConstraints1.gridy = 0;
			
			panel.add(getLblCapsLookKey(), gridBagConstraints1);
			
			final GridBagConstraints gridBagConstraints2 = new GridBagConstraints();
			gridBagConstraints2.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints2.gridx = 1;
			gridBagConstraints2.gridy = 0;
			
			panel.add(getLblNumLookKey(), gridBagConstraints2);
			
			final GridBagConstraints gridBagConstraints3 = new GridBagConstraints();
			gridBagConstraints3.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints3.gridx = 2;
			gridBagConstraints3.gridy = 0;
			
			panel.add(getLblScrollLookKey(), gridBagConstraints3);
			
			final GridBagConstraints gridBagConstraints4 = new GridBagConstraints();
			gridBagConstraints4.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints4.gridx = 3;
			gridBagConstraints4.gridy = 0;
			
			panel.add(getLblLocale(), gridBagConstraints4);
			
			final GridBagConstraints gridBagConstraints5 = new GridBagConstraints();
			gridBagConstraints5.fill = GridBagConstraints.HORIZONTAL;
			gridBagConstraints5.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints5.gridx = 4;
			gridBagConstraints5.gridy = 0;
			
			panel.add(getLblMessage(), gridBagConstraints5);
			
			final GridBagConstraints gridBagConstraints6 = new GridBagConstraints();
			gridBagConstraints6.anchor = GridBagConstraints.EAST;
			gridBagConstraints6.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints6.gridx = 5;
			gridBagConstraints6.gridy = 0;
			
			panel.add(getLblTimer(), gridBagConstraints6);
			
			final GridBagConstraints gridBagConstraints7 = new GridBagConstraints();
			gridBagConstraints7.anchor = GridBagConstraints.EAST;
			gridBagConstraints7.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints7.gridx = 6;
			gridBagConstraints7.gridy = 0;
			
			panel.add(getProgressBar(), gridBagConstraints7);
			
			final GridBagConstraints gridBagConstraints8 = new GridBagConstraints();
			gridBagConstraints8.anchor = GridBagConstraints.EAST;
			gridBagConstraints8.insets = new Insets(0, 0, 0, 5);
			gridBagConstraints8.gridx = 7;
			gridBagConstraints8.gridy = 0;
			
			panel.add(getLblOperatingSystem(), gridBagConstraints8);
		}
		return panel;
	}
	
	/**
	 * 
	 */
	private void initGUI() {
	
		setSize(600, 30);
		setFloatable(false);
		setBorder(BevelBorderFactory.createLoweredBorder());
		
		add(getPanel());
	}
	
	/**
	 * @return the lblCapsLookKey
	 */
	public CapsLookKeyLabel getLblCapsLookKey() {
	
		if(lblCapsLookKey == null) {
			lblCapsLookKey = new CapsLookKeyLabel();
			lblCapsLookKey.setBorder(EtchedBorderFactory.createRaisedBorder());
		}
		
		return lblCapsLookKey;
	}
	
	/**
	 * @return the lblLocale
	 */
	public LocaleLabel getLblLocale() {
	
		if(lblLocale == null) {
			lblLocale = new LocaleLabel();
			lblLocale.setBorder(EtchedBorderFactory.createRaisedBorder());
		}
		
		return lblLocale;
	}
	
	/**
	 * @return the lblMessage
	 */
	public JLabel getLblMessage() {
	
		if(lblMessage == null) {
			lblMessage = new JLabel() {
				
				private static final long serialVersionUID = 3818179565426088703L;
				
				@Override
				public void setText(String text) {
				
					super.setText(text);
					super.setToolTipText(text);
				}
			};
			lblMessage.setBorder(EtchedBorderFactory.createRaisedBorder());
			lblMessage.setMinimumSize(new Dimension(100, 20));
			lblMessage.setPreferredSize(new Dimension(100, 25));
		}
		return lblMessage;
	}
	
	/**
	 * @return the lblNumLookKey
	 */
	public NumLookKeyLabel getLblNumLookKey() {
	
		if(lblNumLookKey == null) {
			lblNumLookKey = new NumLookKeyLabel();
			lblNumLookKey.setBorder(EtchedBorderFactory.createRaisedBorder());
		}
		
		return lblNumLookKey;
	}
	
	/**
	 * @return the lblOperatingSystem
	 */
	public OperatingSystemLabel getLblOperatingSystem() {
	
		if(lblOperatingSystem == null) {
			lblOperatingSystem = new OperatingSystemLabel();
			lblOperatingSystem.setBorder(EtchedBorderFactory.createRaisedBorder());
			lblOperatingSystem.setVisible(false);
		}
		return lblOperatingSystem;
	}
	
	/**
	 * @return the lblScrollLookKey
	 */
	public ScrollLookKeyLabel getLblScrollLookKey() {
	
		if(lblScrollLookKey == null) {
			lblScrollLookKey = new ScrollLookKeyLabel();
			lblScrollLookKey.setBorder(EtchedBorderFactory.createRaisedBorder());
		}
		
		return lblScrollLookKey;
	}
	
	/**
	 * @return the lblTimer
	 */
	public TimerLabel getLblTimer() {
	
		if(lblTimer == null) {
			lblTimer = new TimerLabel();
			lblTimer.setBorder(EtchedBorderFactory.createRaisedBorder());
			lblTimer.setVisible(false);
		}
		return lblTimer;
	}
	
	/**
	 * @return the progressBar
	 */
	public JProgressBar getProgressBar() {
	
		if(progressBar == null) {
			progressBar = new JProgressBar();
			progressBar.setMinimumSize(new Dimension(100, 15));
			progressBar.setBorder(EtchedBorderFactory.createRaisedBorder());
		}
		return progressBar;
	}
	
	/**
	 * @param value
	 */
	public void setMessage(final String value) {
	
		getLblMessage().setText(value);
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleCapsLookKeyLabel(final boolean visible) {
	
		getLblCapsLookKey().setVisible(visible);
		
		COLUMN_WIDTHS[0] = visible ? getLblCapsLookKey().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleNumLookKeyLabel(final boolean visible) {
	
		getLblNumLookKey().setVisible(visible);
		
		COLUMN_WIDTHS[1] = visible ? getLblNumLookKey().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleScrollLookKeyLabel(final boolean visible) {
	
		getLblScrollLookKey().setVisible(visible);
		
		COLUMN_WIDTHS[2] = visible ? getLblScrollLookKey().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleLocaleLabel(final boolean visible) {
	
		getLblLocale().setVisible(visible);
		
		COLUMN_WIDTHS[3] = visible ? getLblLocale().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleMessageLabel(final boolean visible) {
	
		getLblMessage().setVisible(visible);
		
		COLUMN_WIDTHS[4] = visible ? getLblMessage().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleTimerLabel(final boolean visible) {
	
		getLblTimer().setVisible(visible);
		
		COLUMN_WIDTHS[5] = visible ? getLblTimer().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleProgressBar(final boolean visible) {
	
		getProgressBar().setVisible(visible);
		
		COLUMN_WIDTHS[6] = visible ? getProgressBar().getWidth() : 0;
	}
	
	/**
	 * @param visible
	 */
	public void setVisibleOperatingSystemLabel(final boolean visible) {
	
		getLblOperatingSystem().setVisible(visible);
		
		COLUMN_WIDTHS[7] = visible ? getLblOperatingSystem().getWidth() : 0;
	}
}
